#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;

struct stu {
    string *name;
    string *gender;
    int *age;

};
typedef vector<stu*> s1;

void showall(s1 *msg);
void welcome(){
    cout << "----------名片管理系统---------" << endl;
    cout << "1,新增信息" << endl;
    cout << "2,显示所有" << endl;
    cout << "3,查询学生" << endl;
    cout << "4,删除数据" << endl;
    cout << "5,退出系统" << endl;
}



void add(s1 *msg) {

    stu *s = new stu;

    s->name = new string();
    s->gender = new string();
    s->age = new int();
    cout << "学生姓名:";
    cin >> *s->name;
    cout << "学生性别:";
    cin >> *s->gender;
    cout << "学生年龄:";
    cin >> *s->age;
    msg->push_back(s);


}

void showall(s1 *msg) {


    for (stu *s:*msg) {
        cout << *s->name<<endl;
        cout << *s->gender<<endl;
        cout << *s->age<<endl;
    }


}

void query(s1 *msg) {
    cout << "要查询的名字是：";

    string name;
    cin >> name;
    for (auto *stu :*msg) {
        if (*stu->name == name) {
            cout << *stu->name << endl;
            cout << *stu->gender << endl;
            cout << *stu->age << endl;
        }
    }
}

void del(s1 *msg) {
    cout << "要删除的名字是：";
    string name;
    cin >> name;
    for (auto i = 0; i < msg->size(); i++) {
        if (*msg->at(i)->name == name) {
            msg->erase(msg->begin()+i);
            break;
        }
    }
    }




void createVectors(vector<stu*> **msg) {
    *msg = new vector<stu*>();


}


int main() {
    vector<stu*> *msg=nullptr;
    createVectors(&msg);
    while (1) {
        int count=0;
        count++;
        welcome();
        cout<<"请输入选项：";
        int x =0;
        cin>>x;
        switch(x){
            case 1:
                add(msg);
                break;
            case 2:
                showall(msg);
                break;
            case 3:
                query(msg);
                break;
            case 4:
                del(msg);
                break;
            case 5:
                //退出程序
                exit(0);
            default:
                cout << "请输入正确的操作" << endl;
                break;


        }


        if (count > 100)
            break;
    }
    delete msg;
}




